home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / TransparencyTrickUtils.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  3.7 KB  |  107 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.*;
  4.  
  5. //    02/03/97    LAB    Fixed a type-o in the NOTE below.
  6. //     02/15/97    RKM    Put gc and runFinalization in paintComponent
  7. //     02/16/97    RKM    Changed paint call to update as per David E's suggestion
  8.  
  9. //
  10. // NOTE:    If you use this routine, you need to implement TransparencyTrick.
  11. //            Otherwise intersecting your component with another componet that uses
  12. //            these routines will result in a lock up
  13. //
  14.  
  15. /**
  16.  * This class implements the painting method that is used to simulate transparent
  17.  * Components. If you use this class you also need to implement TransparencyTrick.
  18.  * Otherwise intersecting your Component with another Component that uses
  19.  * these routines will result in a lock up.
  20.  */
  21. public class TransparencyTrickUtils
  22. {
  23.     //
  24.     // Implements transparency the bast we can under AWT
  25.     //
  26.     /**
  27.      * This method implements the painting of transparent Components.
  28.      * It does this by painting the Components parent and all the other
  29.      * Components that intersect with the invisible Component.
  30.      * @param drawingComponent the invisible Component "being drawn"
  31.      * @param g the graphics context to use for drawing
  32.      */
  33.     public static void paintComponentsBehind
  34.             (Component    drawingComponent,
  35.              Graphics    g)
  36.     {
  37.         Rectangle myBounds = drawingComponent.bounds();
  38.         
  39.         //First fill my background with myParent
  40.         Container myParent = drawingComponent.getParent();
  41.         paintComponent(drawingComponent, (Component)myParent, myBounds, g);
  42.         
  43.         //Now draw any intersecting components
  44.         Component[] list = myParent.getComponents();
  45.         for (int i = 0; i < list.length; ++i) {
  46.             Component c = list[i];
  47.             if (c != drawingComponent)
  48.                 paintComponent(drawingComponent, c, myBounds, g);
  49.         }
  50.     }
  51.     
  52.     //
  53.     // A utility of paintComponentsBehind
  54.     //
  55.     
  56.     /**
  57.      * This method paints one Component that intsects with the invisible
  58.      * Component. It is a utility routine of paintComponentsBehind.
  59.      * @param drawingComponent the invisible Component "being drawn"
  60.      * @param intersectingComponent the Component that intersects the drawingComponent
  61.      * @param myBounds the bounds of the invisible Component
  62.      * @param g the graphics context to use for drawing
  63.      * @see #paintComponentsBehind
  64.      */
  65.     public static void paintComponent
  66.             (Component    drawingComponent,
  67.              Component    intersectingComponent,
  68.              Rectangle    myBounds,
  69.              Graphics    g)
  70.     {
  71.         //If it's an invisible button, don't draw this component (avoid recursion)
  72.         if (intersectingComponent instanceof TransparencyTrick)
  73.             return;
  74.         
  75.         //Make certain intersectingComponent really does intersect us
  76.         Rectangle icBounds = intersectingComponent.bounds();
  77.         if (icBounds.intersects(myBounds)) {
  78.             Image img = drawingComponent.createImage(icBounds.width, icBounds.height);
  79.             if (img != null) {
  80.                 //Get the graphics object representing the image
  81.                 Graphics imageGraphics = img.getGraphics();
  82.                 if (imageGraphics != null) {
  83.                     //Draw the intersecting component into the offscreen image
  84.                     intersectingComponent.update(imageGraphics);
  85.                     
  86.                     //Draw it to the screen
  87.                     g.drawImage(img, icBounds.x - myBounds.x, icBounds.y - myBounds.y, null);
  88.                     
  89.                     imageGraphics.dispose();
  90.                 }
  91.                 
  92.                 //No use in waiting for the garbage collector, we know it's garbage
  93.                 img.flush();
  94.                 
  95.                 //Flush should call ImageRepresentation.dispose, but it is not,
  96.                 //so we'll have to make certain the finalize for the ImageRepresentation gets called
  97.                 //Since this is a big problem on the Macintosh, we'll only do it for them
  98.                 if (symantec.itools.lang.OS.isMacintosh())
  99.                 {
  100.                     System.gc();
  101.                     System.runFinalization();
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }
  107.